package com.queen.restaurant.advice;

import java.util.Date;

import javax.print.attribute.standard.DateTimeAtCompleted;

import org.apache.log4j.Logger;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;

@Aspect
public class LogAdvice {

	private Logger logger = Logger.getLogger(LogAdvice.class);
	
	@Around("execution(* com.queen.restaurant.controller.*.*(..))")
	public Object logAround(ProceedingJoinPoint jp) throws Throwable{
		long start = new Date().getTime();
		StringBuilder info = new StringBuilder();
		logger = Logger.getLogger(jp.getTarget().getClass());
		info.append("方法名称: " + jp.getSignature().getName() + "\n");
		Object[] args = jp.getArgs();
		if (args != null && args.length > 0) {
			for (int i = 0; i < args.length; i++) {
				info.append("参数类型: " + args[i].getClass().getName() + "_");
				info.append("参数值: " + args[i].toString());
			}
		}
		logger.info(info);
		Object rvt = jp.proceed();
		logger.info("返回值： " + rvt.toString());
		long end = new Date().getTime();
		logger.info("方法执行时长: " + (end - start));
		return rvt;
	}
}
